from pydantic import BaseModel
from typing import Optional, Dict, Any, List
from datetime import datetime

class DatabaseConfig(BaseModel):
    type: str
    host: str
    port: int
    user: str
    password: str
    database: str

# 新增支持多数据库的配置类
class MultiDatabaseConfig(BaseModel):
    type: str
    host: str
    port: int
    user: str
    password: str
    databases: List[str]

class TaskOptions(BaseModel):
    migrate_schema: bool = True
    migrate_data: bool = True
    enable_incremental: bool = True
    filter_condition: Optional[str] = None

class DTSTaskCreate(BaseModel):
    name: str
    source: DatabaseConfig
    target: DatabaseConfig
    options: Optional[TaskOptions] = None

# 新增支持多数据库的任务创建类
class DTSMultiTaskCreate(BaseModel):
    name: str
    source: MultiDatabaseConfig
    target: MultiDatabaseConfig
    options: Optional[TaskOptions] = None

class DTSTaskUpdate(BaseModel):
    name: Optional[str] = None
    source: Optional[DatabaseConfig] = None
    target: Optional[DatabaseConfig] = None
    options: Optional[TaskOptions] = None

class DTSTaskResponse(BaseModel):
    id: int
    name: str
    type: str
    status: str
    source: DatabaseConfig
    target: DatabaseConfig
    options: Optional[TaskOptions] = None
    created_at: datetime
    updated_at: datetime

    class Config:
        from_attributes = True

class DTSTaskRuntimeResponse(BaseModel):
    task_id: int
    checkpoint: Optional[str] = None
    delay_seconds: float = 0.0
    qps: float = 0.0
    last_error: Optional[str] = None

    class Config:
        from_attributes = True

class DTSTaskLogResponse(BaseModel):
    id: int
    task_id: int
    level: str
    message: str
    created_at: datetime

    class Config:
        from_attributes = True